<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"	xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head>
		<script src="//connect.facebook.net/en_US/all.js"></script>
	</h:head>
	<body>
		<div id="fb-root"></div>
		<script>
			// Additional JS functions here
			window.fbAsyncInit = function() {
				FB.init({
			    	appId      	 : '435677693206993', // App ID
			     	channelUrl : 'http://localhost:8080/AutoGuia/fblogin.xhtml', // Channel File
			     	status     	 : true, // check login status
			     	xfbml      	 : true,  // parse XFBML
                    cookie     : true,
			   	});
			};
			
			 // Load the SDK asynchronously
			(function(d) {
				var js, id = 'facebook-jssdk';
				if (d.getElementById(id)) {
					return;
				}
				js = d.createElement('script');
				js.id = id;
				js.async = true;
				js.src = "//connect.facebook.net/en_US/all.js";
				d.getElementsByTagName('head')[0].appendChild(js);
			}(document));

			function login() {
				FB.login(function(response) {
					if (response.authResponse) {
						document.getElementById('hid_acc_tk').value = FB.getAuthResponse()['accessToken'];
						document.getElementById('cmd_link_sv').click();
					}
					else {
						alert('Authentication failed. Please try again.');
					}
				}, {
					scope : 'email,publish_stream,user_photos,friends_about_me'
				});
			}
		</script>
		<h:form prependId="false">
			<h:inputHidden id="hid_acc_tk" value="#{usuarioBean.token}" />
			<p:commandLink id="cmd_link_sv" actionListener="#{usuarioBean.loginFacebook}"/>
			<br/>
			<h:outputLink id="cmd_link_fb" onclick="login(); return false;">
				<h:graphicImage id="bt_img" value="/pics/login_facebook.jpg" width="150" height="35" style="border: 0" />
			</h:outputLink>
		</h:form>
	</body>
</html>
